package 剑指offer;

public class Offer58_JZ44 {
    public String reverseWords(String s) {
        s = s.trim();
        String[] strs = s.split(" ");
        StringBuilder strAll = new StringBuilder();
        for(int index=strs.length-1; index>=0; index--) {
            if ("".equals(strs[index])) {
                continue;
            }
            strAll.append(strs[index]);
            strAll.append(" ");
        }
        return strAll.toString().trim();
    }

    public static void main(String[] args) {
        Offer58_JZ44 demo = new Offer58_JZ44();
        System.out.println(demo.reverseWords("a good   example"));
    }
}
